Post

Replies

Boosts

Views

Activity

How to align slider labels in SwiftUI
On macOS we can add labels directly to SwiftUI slider. Has someone found a way how we can align two or more sliders in a VStack?- label text right aligned- all labels should have the same width (given by the largest text)- all slider bars should have the same but flexible width within the containers frame
4
0
3.6k
Dec ’19
How to use a SwiftUI touchbar with a NSWindow
Inside the app delegate I uses a simple SwiftUI view as the root for my macOS main window.func applicationDidFinishLaunching(_ aNotification: Notification) { // Create the SwiftUI view that provides the window contents. let contentView = ContentView().touchBar(myTouchbar) // Create the window and set the content view. window = NSWindow( contentRect: NSRect(x: 0, y: 0, width: 480, height: 300), styleMask: [.titled, .closable, .miniaturizable, .resizable, .fullSizeContentView], backing: .buffered, defer: false) window.center() window.setFrameAutosaveName("Main Window") window.contentView = NSHostingView(rootView: contentView) window.makeKeyAndOrderFront(nil) }This contentView has a touchbar asigned to it. If the contentView is a simple view that can hold a focus (like a Textield) then the touchbar becomes visible on my MacBook. But in my application the contentView (the root view of the NSWindow) is a layout container like a HSplitView. In this case the window appears but the touchbar is not visible. How can I use a SwiftUI touchbar with a window without focusable or input elements so that the touchbar is always visible together with the window.
1
0
1.1k
Dec ’19
Why does @Published removes the codable protocol conformance
I have a simple class conforming to the codable protocol. Here is an example which is the same like in the developer documentation...class Landmark: Codable { var name: String var foundingYear: Int }Because the two properties inside the class body are basic Swift types the compiler has nothing to complain.But if I want to edit these properties using SwiftUI I must also make sure that the class conforms also to the ObservableObject protocol.class Landmark: Codable, ObservableObject { @Published var name: String @Published var foundingYear: Int }Now I get an Xcode error message that type Landmark does not conform to the codable protocol anymore.This is something I cannot understand. The property wrapper @Published should not change the type of the properties String and Int. The codable conformance should imho still be given to the class without additional lines of codes.
4
0
3.6k
Dec ’19
How to position child views within a parent view
Please apologize if this question is really trival. I implementent a content view with two buttons on it. One button should be 8px below the top, the other 8px above the bottom. Maybe I am doing something wrong. But I would use a simple ZStack here. Only problem is that I can set only one alignment for the ZStack at a time. So I can either align all views from the top border or from the bottom border but not one from the top and one from the bottom. Is there a way to solve this layout problem with these three views and a ZStack?
3
0
2.8k
Apr ’20
How to add a label to the side of a TextField on macOS
In the latest beta most of the SwiftUI controls have now a labels that are displayed on the left side of the controls. The alignment of the controls and labels works pretty well. Also the TextField is aligned with the other controls. But its title parameter is used as a placeholder inside the TextField while the left side of the TextField is empty. In my application I have a SwiftUI form with some controls and some number input fields. After the user has entered values the placeholders are not visible and the user cannot see the meaning of each value he entered anymore. Is there a way that the title of a TextField can be displayed as a label on the left side similar to the other controls instead of a placeholder inside the input field?
2
0
1k
Jul ’20
Swift TextField with label on macOS
Why is there no label for SwiftUI TextField but only a placeholder text? Or is there a modifier that I haven't found yet or a style property? On macOS every control seems to have now a label that is shown on the left side and that is correctly aligned with the other controls in a form. The TextField is also aligned with the other controls but has an empty space left to it. Using the label parameter as a placeholder is not very helpful having multiple textfields and the user entered already some values in them. In this case you cannot see anymore the meaning for all these values. I tried to implement a HStack with a Text and a TextField as a workaround but had trouble to align it with the other controls that have already label parameters in their SwiftUI syntax.
2
0
1.7k
Jul ’20
How to add a label to a SwiftUI Textfield in macOS
Is there a way to add a label to SwiftUI Textfield inside a SwiftUI Form so that the label is aligned with the other controls? Placeholder in textfields will disappear when you enter values so this won't help much. All other controls have labels in macOS form with the same width so that their controls are correctly aligned. Textfield seems not to have this option. I tried several workaround like HStacks of Text and Textfields or custom alignment guides but without success.
2
1
4.0k
Oct ’20
How to implement a Xcode style SwiftUI tabview
Above Xcode's navigator area or uitilty area there are some buttons for switching the content views below. I implemented the standard SwiftUI TabView and also a Picker with the segmented style to get the same appearance in my macOS app but both are looking different. Plain buttons in a HStack above my content area are solving the problem. But it seems more like a workaround. Is there maybe a simpler solution to implement a Xcode style tabview that I have overseen.
0
0
417
Oct ’20
Metal Triple Buffering and Capture Scope
Can someone help me with this hopefully simple problem? I use triple buffering in my metal app similar to Apples Best Practice Guide. Three threads are simultaneously encoding rendering commands to command buffers enqueued in into one MTLCommandQueue. What is the best way to debug this scenario with the Xcode's frame debugger? I have some problems setting the capture scopes begin and end point in such a multithreaded environment to isolate the commands encoded from one thread.
1
0
900
Oct ’20
Xcode app cannot see the driver anymore on Big Sur
My app uses an external PCI board connected with the thunderbolt cable to a 2019 MacBook Pro (Big Sur beta 10). The strange thing is that the external example apps coming with the driver can communicate with it. The same apps compiled with Xcode 12.2 beta cannot communicate with the driver even it is the same code. When I installed the driver together with the example apps a window appeared that these software come from an external source and the usage must be granted in the security settings. I did it and therefor the apps work fine. Is there maybe a similar setting now in Xcode where I must allow the compiled app to communicate with third party drivers? The code of the app was unchanged and worked with a previous macOS version.
3
0
936
Oct ’20
Search for max value coordinate in a MTLTexture
I struggle with the implementation of a compute kernel to solve a relative simple search problem. I want to find the coordinate with the highest pixel value within a MTLTexture. I have already an implementation where I copy the content of the MTLTexture into CPU memory and apply some min/max commands from the accelerate framework. But maybe there is also a simple solution for this task using Metal which I haven't found yet.
1
0
934
Jan ’21
High battery drain using Xcode 13
I have two Mac Book Pro 16'' 2019. On both I see a very high battery drain using Xcode 13 while using the simulator. Even when the app is not running only the simulator is launched in the background the MacBook gets very hot and the battery drains empty very fast. For the beta this was ok. But with the RC I expected that this was only a temporary problem. Does some else has this problem also?
16
1
6k
Sep ’21